import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/views/layout/Layout'

/** note: Submenu only appear when children.length>=1
 *  detail see  https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 **/

/**
* hidden: false                   if `hidden:true` will not show in the sidebar(default is false)
* alwaysShow: true               if set true, will always show the root menu, whatever its child routes length
*                                if not set alwaysShow, only more than one route under the children
*                                it will becomes nested mode, otherwise not show the root menu
* redirect: noredirect           if `redirect:noredirect` will no redirect in the breadcrumb
* name:'router-name'             the name is used by <keep-alive> (must set!!!)
* meta : {
    perms: ['GET /aaa','POST /bbb']     will control the page perms (you can set multiple perms)
    title: 'title'               the name show in submenu and breadcrumb (recommend set)
    icon: 'svg-name'             the icon show in the sidebar,
    noCache: true                if true ,the page will no be cached(default is false)
  }
**/
export const constantRouterMap = [
  {
    path: '/redirect',
    component: Layout,
    hidden: true,
    children: [
      {
        path: '/redirect/:path*',
        component: () => import('@/views/redirect/index')
      }
    ]
  },
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },
  {
    path: '/register',
    component: () => import('@/views/register/index'),
    hidden: true
  },
  {
    path: '/register-success',
    component: () => import('@/views/register/success'),
    hidden: true
  },
  {
    path: '/active-success',
    component: () => import('@/views/register/active-success'),
    hidden: true
  },
  {
    path: '/shop-info',
    component: () => import('@/views/register/shop-info'),
    hidden: true
  },
  {
    path: '/auth-redirect',
    component: () => import('@/views/login/authredirect'),
    hidden: true
  },
  {
    path: '/404',
    component: () => import('@/views/errorPage/404'),
    hidden: true
  },
  {
    path: '/401',
    component: () => import('@/views/errorPage/401'),
    hidden: true
  },
  {
    path: '',
    component: Layout,
    redirect: 'dashboard',
    children: [
      {
        path: 'dashboard',
        component: () => import('@/views/dashboard/index'),
        name: 'Dashboard',
        meta: { title: '概览', icon: 'dashboard', noCache: true }
      }
    ]
  }
]

export default new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRouterMap
})

export const asyncRouterMap = [
  {
    path: '/statistical',
    component: Layout,
    redirect: 'noredirect',
    alwaysShow: true,
    name: 'statistical',
    meta: {
      title: '客户登记管理',
      icon: 'peoples'
    },
    children: [
      {
        path: 'user',
        component: () => import('@/views/user/user'),
        name: 'user',
        meta: {
          title: '客户查询',
          perms: ['客户查询'],
          noCache: true
        }
      }
    ]
  },
  {
    path: '/visit',
    component: Layout,
    redirect: 'noredirect',
    alwaysShow: true,
    name: 'visit',
    meta: {
      title: '客户到访管理',
      icon: 'table'
    },
    children: [
      {
        path: 'record',
        component: () => import('@/views/visit/record'),
        name: 'visit-record',
        meta: {
          title: '到访记录查询',
          perms: ['到访记录查询'],
          noCache: true
        }
      },
      {
        path: 'remark',
        component: () => import('@/views/visit/remark-counts'),
        name: 'remark-counts',
        meta: {
          title: '登记次数查询',
          perms: ['登记次数查询'],
          noCache: true
        }
      },
      {
        path: 'visit',
        component: () => import('@/views/visit/visit'),
        name: 'visit-counts',
        meta: {
          title: '到访次数查询',
          perms: ['到访次数查询'],
          noCache: true
        }
      },
      {
        path: 'visit/more',
        component: () => import('@/views/visit/visit-more'),
        name: 'visit-more',
        meta: {
          title: '到访次数查询',
          perms: ['到访次数查询'],
          noCache: true
        },
        hidden: true
      },
      {
        path: 'more',
        component: () => import('@/views/visit/more'),
        name: 'more',
        meta: {
          title: '登记次数查询',
          perms: ['登记次数查询'],
          noCache: true
        },
        hidden: true
      }
    ]
  },
  {
    path: '/customer-flow',
    component: Layout,
    redirect: 'noredirect',
    alwaysShow: true,
    name: 'customerFlow',
    meta: {
      title: '统计分析',
      icon: 'chart'
    },
    children: [
      {
        path: 'customer',
        component: () => import('@/views/analysis/customer'),
        name: 'customer',
        meta: {
          title: '客户登记分析',
          perms: ['客户登记分析'],
          noCache: true
        },
        hidden: false
      },
      {
        path: 'remark',
        component: () => import('@/views/analysis/remark'),
        name: 'remark',
        meta: {
          title: '到访记录分析',
          perms: ['到访记录分析'],
          noCache: true
        },
        hidden: false
      }
    ]
  },
  {
    path: '/shop',
    component: Layout,
    redirect: 'shop',
    children: [
      {
        path: 'shop',
        component: () => import('@/views/shop/index'),
        name: 'shop',
        meta: { title: '门店管理', icon: 'people', noCache: true, perms: ['门店管理'] }
      }
    ]
  },
  {
    path: '/system',
    component: Layout,
    redirect: 'noredirect',
    alwaysShow: true,
    name: 'system',
    meta: {
      title: '系统管理',
      icon: 'lock'
    },
    children: [
      {
        path: 'role',
        component: () => import('@/views/system/role/role'),
        name: 'role',
        meta: {
          title: '角色管理',
          perms: ['角色管理'],
          noCache: true
        },
        hidden: false
      },
      {
        path: 'role/new',
        component: () => import('@/views/system/role/new'),
        name: 'new',
        meta: {
          title: '新增角色',
          perms: ['角色管理'],
          noCache: true
        },
        hidden: true
      },
      {
        path: 'role/edit',
        component: () => import('@/views/system/role/edit'),
        name: 'editRole',
        meta: {
          title: '编辑角色',
          perms: ['角色管理'],
          noCache: true
        },
        hidden: true
      },
      {
        path: 'role/desc',
        component: () => import('@/views/system/role/desc'),
        name: 'editRole',
        meta: {
          title: '查看角色',
          perms: ['角色管理'],
          noCache: true
        },
        hidden: true
      },
      {
        path: 'account/new',
        component: () => import('@/views/system/account/new'),
        name: 'newAccount',
        meta: {
          title: '新建账号',
          noCache: true,
          perms: ['账号管理']
        },
        hidden: true
      },
      {
        path: 'account',
        component: () => import('@/views/system/account/account'),
        name: 'account',
        meta: {
          title: '账号管理',
          noCache: true,
          perms: ['账号管理']
        }
      },
      {
        path: 'account/editor',
        component: () => import('@/views/system/account/editor'),
        name: 'editor',
        meta: {
          title: '账号编辑',
          noCache: true,
          perms: ['账号管理']
        },
        hidden: true
      }
    ]
  },
  {
    path: '/promote',
    component: Layout,
    redirect: 'promote',
    children: [
      {
        path: 'promote',
        component: () => import('@/views/promote/index'),
        name: 'promote',
        meta: { title: '推广管理', icon: 'example', perms: ['推广管理'], noCache: true }
      }
    ]
  },
  {
    path: '/profile',
    component: Layout,
    redirect: 'noredirect',
    alwaysShow: true,
    children: [
      {
        path: 'password',
        component: () => import('@/views/profile/password'),
        name: 'password',
        meta: { title: '修改密码', noCache: true }
      }
    ],
    hidden: true
  },
  { path: '*', redirect: '/404', hidden: true }
]
